package org.zjx.command.service;

import lombok.Getter;
import org.zjx.command.Command;
import org.zjx.core.IWindow;
import org.zjx.dubbo.DubboServiceFactory;
import org.zjx.model.game.Screen;
import org.zjx.service.NpcService;
import org.zjx.service.ScreenService;

public class ScreenServerCommand extends Command {
    private final int screenId;
    private final String screenName;
    @Getter
    private Screen screen;
    private static ScreenService screenService;

    public ScreenServerCommand(IWindow targetWindow,  int screenId) {
        super(targetWindow, false, null);
        this.screenId = screenId;
        this.screenName = null;
    }

    public ScreenServerCommand(IWindow targetWindow,  String screenName) {
        super(targetWindow, false, null);
        this.screenId = 0;
        this.screenName = screenName;
    }

    @Override
    protected void doExecute() throws Exception {
        if (screenService == null) {
            screenService = DubboServiceFactory.getService(ScreenService.class, "screen.service.url");
        }
        if (screenId != 0) {
            screen = screenService.getScreenById(screenId);
        }else if (screenName != null) {
            screen = screenService.getScreen(screenName);
        }
    }
}
